<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.text.DateFormat"%>
<%@page import="Entity.Event"%>
<%@page import="VietDQ.VietDQSessionBeanLocal"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.naming.Context"%>
<h2>Top News Events</h2>
<%
    Context ctx = new InitialContext();
    VietDQSessionBeanLocal VLocal = (VietDQSessionBeanLocal) ctx.lookup("VietDQSessionBeanLocalJNDI");
    Event[] listTopEv = VLocal.findTop5NewEvent();
    DateFormat dff = new SimpleDateFormat("dd/MM/yyyy");
    if(listTopEv.length >= 6)
        {
    for (int i = 0; i < 6; i++) {
    String date = dff.format(listTopEv[i].getDateCreate());
%>
            <div class="news_box">
                <a href="VietDQServlet?action=USDetailEV&txtid=<%= listTopEv[i].getEvID() %>"><%=listTopEv[i].getEvName()%></a>
                <p class="post_info">Posted by <span>Admin</span> on <span><%=date %></span></p>
            </div>
<%
                }
    }else{

         for (int i = 0; i < listTopEv.length; i++) {
        String date = dff.format(listTopEv[i].getDateCreate());
%>    
    <div class="news_box">
                <a href="VietDQServlet?action=USDetailEV&txtid=<%= listTopEv[i].getEvID() %>"><%=listTopEv[i].getEvName()%></a>
                <p class="post_info">Posted by <span>Admin</span> on <span><%=date %></span></p>
     </div>
<%
                }
        }
%>